package gew.beans;

import gew.data.IndicatorSummaryIndicator;
import gew.data.IndicatorSummaryItem;
import gew.metadata.CustomSql;
import gew.system.Constants;
import gew.system.Labels;
import gew.system.RequestParameter;
import gew.utils.SqlUtils;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;

@ManagedBean(name = "hmBn")
@RequestScoped
public class HomeBean extends BaseBean {

    private RequestParameter rp;

    private ArrayList<IndicatorSummaryIndicator> indicators;
    private ArrayList<IndicatorSummaryItem> results;
    private String updateDate;

    @PostConstruct
    public void init() {
        HttpServletRequest r = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
        rp = new RequestParameter(r, dvs);
        logRequest(r, Constants.SECTION_HOME, rp.getRequestURI());
        
        String q1 = CustomSql.getIndicatorsSummary(rp.getLocaleUrlCode());
        results = df.getIndicatorSummaryItems(q1);

        String q2 = CustomSql.getIndicatorsSummaryIndicators(rp.getLocaleUrlCode());
        indicators = df.getIndicatorSummaryIndicators(q2);

        updateDate = DateFormat.getDateInstance(DateFormat.FULL, rp.getLocale()).format(new Date());
    }

    public String getUI_TITLE_MAIN() {
        return Labels.get_UI_TITLE_MAIN(rp.getLocale());
    }

    public Iterable<IndicatorSummaryItem> getResults() {
        return results;
    }

    public Iterable<IndicatorSummaryIndicator> getIndicators() {
        return indicators;
    }

    public String getLabelCountry() {
        return Labels.get_UI_TITLE_COUNTRY(rp.getLocale());
    }

    public String getLabelTrade() {
        return Labels.get_UI_MENU_TRADE_HEADER(rp.getLocale());
    }

    public String getLabelIndicators() {
        return Labels.get_UI_MENU_INDICATORS_HEADER(rp.getLocale());
    }

    public String getLabelIndustries() {
        return Labels.get_UI_MENU_INDUSTRIES_HEADER(rp.getLocale());
    }

    public String getInfoTrade() {
        return Labels.get_UI_INFO_TRADE(rp.getLocale());
    }

    public String getInfoIndicators() {
        return Labels.get_UI_INFO_INDICATORS(rp.getLocale());
    }

    public String getInfoIndustries() {
        return Labels.get_UI_INFO_INDUSTRIES(rp.getLocale());
    }

    public String getLocaleUrlCode() {
        return rp.getLocaleUrlCode();
    }

    public String getIndicatorsUrl() {
        return rp.getContextPath()
                .concat(SqlUtils.SLASH)
                .concat(rp.getLocaleUrlCode())
                .concat(SqlUtils.SLASH)
                .concat(Constants.SECTION_INDICATORS);
    }

    public String getIndustriesUrl() {
        return rp.getContextPath()
                .concat(SqlUtils.SLASH)
                .concat(rp.getLocaleUrlCode())
                .concat(SqlUtils.SLASH)
                .concat(Constants.SECTION_INDUSTRIES);
    }

    public String getTradeUrl() {
        return rp.getContextPath()
                .concat(SqlUtils.SLASH)
                .concat(rp.getLocaleUrlCode())
                .concat(SqlUtils.SLASH)
                .concat(Constants.SECTION_TRADE_SUMMARY)
                .concat(SqlUtils.SLASH)
                .concat(Labels.get_PARAM_DEFAULT_COMMODITY_GROUP_TYPE_CODE_VALUE(rp.getLocale()))
                .concat(SqlUtils.SLASH)
                .concat(Labels.get_PARAM_DEFAULT_TRADE_SUMMARY_COUNTRY(rp.getLocale()));
    }

    public String getUpdateDate() {
        return updateDate;
    }

    public String getUI_UNIT_OF_MEASURE() {
        return Labels.get_UI_UNIT_OF_MEASURE(rp.getLocale());
    }

    public String getUI_PREVIOUS_VALUE() {
        return Labels.get_UI_PREVIOUS_VALUE(rp.getLocale());
    }

    public String getUI_FREQUENCY() {
        return Labels.get_UI_FREQUENCY(rp.getLocale());
    }

    public String getUI_UPDATE_TIME() {
        return Labels.get_UI_UPDATE_TIME(rp.getLocale());
    }

    public String getUI_DATA_SOURCE() {
        return Labels.get_UI_DATA_SOURCE(rp.getLocale());
    }

    public String getUI_PERIOD() {
        return Labels.get_UI_TITLE_PERIOD(rp.getLocale());
    }

    public String getUI_FOOTER_HOME() {
        return Labels.get_UI_FOOTER_HOME(rp.getLocale());
    }

    public String getKeyWords() {
        return Labels.get_META_KEY_WORDS_HOME(rp.getLocale());
    }

}
